

var request;
var xmlHttp ;
var functionname;

function popUpAddChild()


{


      var window2 = window.open('../pages/AddChild.tiles','myWindow','width=790,height=520,scrollbars=yes,menubar=no,status=yes,resizable=yes,directories=false,location=1,left=0,top=0');
      // var testwin=window.open('../pages/AddChild.tiles', 'popupWindowName', 'dependent=yes, menubar=no, toolbar=no'); 
      
}

	function AddCustomer()
		{	 
		 var Parentname=document.getElementById("addChildparent").options[document.getElementById("addChildparent").selectedIndex].value;
		 
         var Scope=document.getElementById("addChildScope").options[document.getElementById("addChildScope").selectedIndex].value;
         var Country=document.getElementById("addChildCountry").options[document.getElementById("addChildCountry").selectedIndex].value;
         var ShortName=document.getElementById("addChildshortName").value;
         var LongName=document.getElementById("addChildlongName").value;
        //var  Status=document.getElementById("addChildStatus").options[document.getElementById("addChildStatus").selectedIndex].value;
         var  Status="O";
         var  EnId=document.getElementById("addChildentity").options[document.getElementById("addChildentity").selectedIndex].value;
         var System=document.getElementById("addChildSystem").options[document.getElementById("addChildSystem").selectedIndex].value;
         var  Type=document.getElementById("addChildType").options[document.getElementById("addChildType").selectedIndex].value;
         var classfication=document.getElementById("addChildClassification").options[document.getElementById("addChildClassification").selectedIndex].value;
         var  CallbackMethod=document.getElementById("addChildcallback").options[document.getElementById("addChildcallback").selectedIndex].value;
         var  ReturnPriority=document.getElementById("addChildcollreturn").options[document.getElementById("addChildcollreturn").selectedIndex].value;
		  var AutoBorrowRet=document.getElementById("addChildAutoBorrowReturn").checked;
		  var Autowrap=document.getElementById("addChildautowarp").checked;
		
		   if(AutoBorrowRet="true")
         {
            AutoBorrowRet="Y";
         }
        else
         {
           AutoBorrowRet="N";
         }

          
         if(Autowrap="true")
         {
            Autowrap="Y";
         }
        else
         {
           Autowrap="N";
         }



         var url = "../AddCustomer?Parentname="+Parentname+"&Scope="+Scope+"&Country="+Country+"&ShortName="+ShortName+"&LongName="+LongName+"&Status="+Status+"&EnId="+EnId+"&System="+System+"&Type="+Type+"&AutoBorrowRet="+AutoBorrowRet+"&Autowrap="+Autowrap+"&CallbackMethod="+CallbackMethod+"&ReturnPriority="+ReturnPriority+"&classfication="+classfication;
		  
         alert(url);
         saveRequest(url);
}


function SerachCustomer()
{
    var  EnId=document.getElementById("SearchEntityId").options[document.getElementById("SearchEntityId").selectedIndex].value;
    var Name=document.getElementById("name").value;
    var url = "../CustomerSerachServelt?EnId="+EnId+"&Name="+Name;
      // document.Customerlist.action=url;
	  // document.Customerlist.submit();

     saveRequest(url);

}
function AddContact()
		{
		alert("AddContact");
		 var contact=document.getElementById("contactnew").value;
		  var CuId=document.getElementById("ideltaCuid").value;
		    var coid=CuId;
         var dept=document.getElementById("dept").value;
         var phone=document.getElementById("phone").value;
         var fax=document.getElementById("fax").value;
         var email=document.getElementById("email").value;
		   var web=document.getElementById("web").value;
		    var address=document.getElementById("address").value;
         var url = "../AddContact?dept="+dept+"&contact="+contact+"&phone="+phone+"&fax="+fax+"&email="+email+"&web="+web+"&address="+address+"&CuId"+CuId+"&coid"+coid;		  
         alert(url);
         saveRequest(url);
}
function AddMap(){
var system=document.getElementById("sys").value;
var alias=document.getElementById("alias").value;
 var url = "../AddMap?system="+system+"&alias="+alias;		  
         alert(url);
         saveRequest(url);

}

function AddParam(){
var pName=document.getElementById("pName").value;
var pValue=document.getElementById("pValue").value;
 var url = "../AddParam?pName="+pName+"&pValue="+pValue;		  
         alert(url);
         saveRequest(url);

}
function SaveCustomer()
{
 
         // this servelt calling used for Save the details of a customer 
         functionname="SaveCustomer";
         
        
         var CuId=document.getElementById("ideltaCuid").value;
         var Scope=document.getElementById("scope").options[document.getElementById("scope").selectedIndex].value;
         var Country=document.getElementById("country").options[document.getElementById("country").selectedIndex].value;
         var ShortName=document.getElementById("shname").value;
         var LongName=document.getElementById("longname").value;
         var  Status=document.getElementById("Status").options[document.getElementById("Status").selectedIndex].value;
         
         if(Status="OPEN")
         {
            Status="O";
         }
        else
         {
           Status="C";
         }

         var  EnId=document.getElementById("entity").options[document.getElementById("entity").selectedIndex].value;
         var System=document.getElementById("system").options[document.getElementById("system").selectedIndex].value;
         var  Type=document.getElementById("type").options[document.getElementById("type").selectedIndex].value;
         var  AutoBorrowRet=document.getElementById("AutoBorrowReturn").value;
         if(AutoBorrowRet="true")
         {
            AutoBorrowRet="Y";
         }
        else
         {
           AutoBorrowRet="N";
         }

          var  Autowrap=document.getElementById("autowarp").value;
         if(Autowrap="true")
         {
            Autowrap="Y";
         }
        else
         {
           Autowrap="N";
         }

         var  CallbackMethod=document.getElementById("CallBack").options[document.getElementById("CallBack").selectedIndex].value;
         var  ReturnPriority=document.getElementById("return").options[document.getElementById("return").selectedIndex].value;
          var  Rows="1";

         alert(CuId+":"+Scope+":"+Country+":"+ShortName+":"+LongName+":"+Status+":"+EnId+":"+System+":"+Type+":"+AutoBorrowRet+":"+Autowrap+":"+CallbackMethod+":"+ReturnPriority)

         /*
         
         var  FeeType=document.getElementById("FeeType").options[document.getElementById("FeeType").selectedIndex].value;
         var  ProfitShare=document.getElementById("ProfitShare").options[document.getElementById("ProfitShare").selectedIndex].value;
         

         
         var  CallbackCutOff=document.getElementById("CallbackCutOff").options[document.getElementById("CallbackCutOff").selectedIndex].value;
         var  LastResort=document.getElementById("LastResort").options[document.getElementById("LastResort").selectedIndex].value;
         
         var  Rows="1";

          */  

         // main tab

         /*
         var Type=document.getElementById("Type").options[document.getElementById("Type").selectedIndex].value;
         var ShortName=document.getElementById("ShortName").value;
         var LongName=document.getElementById("LongName").value; 
         var  System=document.getElementById("System").options[document.getElementById("System").selectedIndex].value;
         var  Status=document.getElementById("Status").options[document.getElementById("Status").selectedIndex].value;
         var  FeeType=document.getElementById("FeeType").options[document.getElementById("FeeType").selectedIndex].value;
         var  ProfitShare=document.getElementById("ProfitShare").options[document.getElementById("ProfitShare").selectedIndex].value;
         var  EnId=document.getElementById("EntityId").options[document.getElementById("EntityId").selectedIndex].value;
         var  AutoBorrowRet=document.getElementById("AutoBorrowRet").value;
         var  Autowrap=document.getElementById("Autowrap").value;
         var  CallbackMethod=document.getElementById("CallbackMethod").options[document.getElementById("CallbackMethod").selectedIndex].value;
         var  CallbackCutOff=document.getElementById("CallbackCutOff").options[document.getElementById("CallbackCutOff").selectedIndex].value;
         var  LastResort=document.getElementById("LastResort").options[document.getElementById("LastResort").selectedIndex].value;
         var  ReturnPriority=document.getElementById("ReturnPriority").options[document.getElementById("ReturnPriority").selectedIndex].value;
         var  Rows="1";
         */
         var url = "../CustomerUpdate?CuId="+CuId+"&Scope="+Scope+"&Country="+Country+"&ShortName="+ShortName+"&LongName="+LongName+"&Status="+Status+"&EnId="+EnId+"&System="+System+"&Type="+Type+"&AutoBorrowRet="+AutoBorrowRet+"&Autowrap="+Autowrap+"&CallbackMethod="+CallbackMethod+"&ReturnPriority="+ReturnPriority+"&Rows="+Rows;
         alert(url);
         saveRequest(url);
}


function getdata(str)
{
   // this servelt calling used for get details of customer on click of the node 
    functionname="getdata";
   var url = "../CustomerServlet?CustomerAccountID="+str;
   alert(url);
   sendRequest(url);

}


function getRequestObject() {
  if (window.ActiveXObject) {
    return(new ActiveXObject("Microsoft.XMLHTTP"));
  } else if (window.XMLHttpRequest) {
    return(new XMLHttpRequest());
  } else {
    return(null);
  }
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


function saveRequest(address) {
  xmlHttp = GetXmlHttpObject();
  xmlHttp.onreadystatechange = showSaveResponseText;
  xmlHttp.open("GET", address, false);
  xmlHttp.send(null);
}


function showSaveResponseText() {
  if ((xmlHttp.readyState == 4) &&
      (xmlHttp.status == 200)) {


              // alert(xmlHttp.responseText);

              // var xmlDoc=xmlHttp.responseXML.documentElement;
  }
}



function sendRequest(address) {
  xmlHttp = GetXmlHttpObject();
  xmlHttp.onreadystatechange = showResponseText;
  xmlHttp.open("GET", address, true);
  xmlHttp.send(null);
}


function showResponseText() {
  if ((xmlHttp.readyState == 4) &&
      (xmlHttp.status == 200)) {


              // alert(xmlHttp.responseText);

               var xmlDoc=xmlHttp.responseXML.documentElement;

                  /*
                  UpdateList("CountryId",xmlDoc.getElementsByTagName("COUNTRY")[0].childNodes[0].nodeValue);
                  UpdateList("ScopeId",xmlDoc.getElementsByTagName("SCOPE")[0].childNodes[0].nodeValue);
                   UpdateList("EntityId",xmlDoc.getElementsByTagName("ENTITYCODE")[0].childNodes[0].nodeValue);
                 */

                 // for main 
                  document.getElementById("longname").value=xmlDoc.getElementsByTagName("LONGNAME")[0].childNodes[0].nodeValue;
                  document.getElementById("shname").value=xmlDoc.getElementsByTagName("SHORTNAME")[0].childNodes[0].nodeValue;
                  UpdateList("type",xmlDoc.getElementsByTagName("TYPE")[0].childNodes[0].nodeValue);
                  UpdateList("country",xmlDoc.getElementsByTagName("COUNTRY")[0].childNodes[0].nodeValue);
                  UpdateList("scope",xmlDoc.getElementsByTagName("SCOPE")[0].childNodes[0].nodeValue);
                  UpdateList("system",xmlDoc.getElementsByTagName("SYSTEM")[0].childNodes[0].nodeValue);
                  UpdateList("status",xmlDoc.getElementsByTagName("STATUS")[0].childNodes[0].nodeValue);
                   UpdateList("entity",xmlDoc.getElementsByTagName("ENTITYCODE")[0].childNodes[0].nodeValue);
                     document.getElementById("AutoBorrowReturn").checked=xmlDoc.getElementsByTagName("AUTOBORROWRET")[0].childNodes[0].nodeValue;
                      document.getElementById("autowarp").checked=xmlDoc.getElementsByTagName("AUTOWARP")[0].childNodes[0].nodeValue;
                     UpdateList("CallBack",xmlDoc.getElementsByTagName("CALLBACKMETHOD")[0].childNodes[0].nodeValue);
                     UpdateList("collreturn",xmlDoc.getElementsByTagName("COLLRETURNPRIORITY")[0].childNodes[0].nodeValue);
                     UpdateList("return",xmlDoc.getElementsByTagName("RETURNPRIORITY")[0].childNodes[0].nodeValue);

                 //  UpdateList("classification",xmlDoc.getElementsByTagName("ENTITYCODE")[0].childNodes[0].nodeValue);



                  // upadteing trade 

                  document.getElementById("collateralType").value=xmlDoc.getElementsByTagName("COLLATERALTYPE")[0].childNodes[0].nodeValue;
                  document.getElementById("cashMargin").value=xmlDoc.getElementsByTagName("CASHMARGIN")[0].childNodes[0].nodeValue;
                  document.getElementById("nonCashMargin").value=xmlDoc.getElementsByTagName("NONCASHMARGIN")[0].childNodes[0].nodeValue;
                  document.getElementById("cashPoolMargin").value=xmlDoc.getElementsByTagName("CASHPOOLMARGIN")[0].childNodes[0].nodeValue;
                  document.getElementById("settleMode").value=xmlDoc.getElementsByTagName("SETTLEMENTMODE")[0].childNodes[0].nodeValue;
                   document.getElementById("cashSettleMode").value=xmlDoc.getElementsByTagName("CASHSETTLEMENTMODE")[0].childNodes[0].nodeValue;
                  document.getElementById("minFee").value=xmlDoc.getElementsByTagName("MINFEE")[0].childNodes[0].nodeValue;
                    document.getElementById("minFeeCurrency").value=xmlDoc.getElementsByTagName("MINFEECURRENCY")[0].childNodes[0].nodeValue;
                     UpdateList("mod2agreed",xmlDoc.getElementsByTagName("MOD2AGREED")[0].childNodes[0].nodeValue);
                    document.getElementById("mod2ExpDate").value=xmlDoc.getElementsByTagName("MOD2EXPDATE")[0].childNodes[0].nodeValue;
                     UpdateList("prinicipalagent",xmlDoc.getElementsByTagName("PRINCIPAL")[0].childNodes[0].nodeValue);
                    document.getElementById("tradeAuthor").value=xmlDoc.getElementsByTagName("TRADEAUTHOR")[0].childNodes[0].nodeValue;
                     document.getElementById("prepayDayCash").value=xmlDoc.getElementsByTagName("PREPAYDAYCASH")[0].childNodes[0].nodeValue;
                     document.getElementById("prepayNonCash").value=xmlDoc.getElementsByTagName("PREPAYNONCASH")[0].childNodes[0].nodeValue;
                       document.getElementById("prepayCashPool").value=xmlDoc.getElementsByTagName("PREPAYCASHPOOL")[0].childNodes[0].nodeValue;
                       document.getElementById("hkRegNum").value=xmlDoc.getElementsByTagName("HKREGNUM")[0].childNodes[0].nodeValue;
                       document.getElementById("hkRegDate").value=xmlDoc.getElementsByTagName("HKREGDATE")[0].childNodes[0].nodeValue;
                       document.getElementById("nonCashHaircut").value=xmlDoc.getElementsByTagName("NONCASHHAIRCUT")[0].childNodes[0].nodeValue;
                       document.getElementById("collAircutEquity").value=xmlDoc.getElementsByTagName("COLLAIRCUTEQUITY")[0].childNodes[0].nodeValue;
                  
                   //updating HKPBReg
                           
                           document.getElementById("pbhkRegNum").value=xmlDoc.getElementsByTagName("PBHKREGNUM")[0].childNodes[0].nodeValue;
                           document.getElementById("pbhkRegDate").value=xmlDoc.getElementsByTagName("PBHKREGDATE")[0].childNodes[0].nodeValue;
                           UpdateList("sbaOverride",xmlDoc.getElementsByTagName("SBAOVERRIDE")[0].childNodes[0].nodeValue);
                           document.getElementById("overrideDate").value=xmlDoc.getElementsByTagName("OVERRIDEDATE")[0].childNodes[0].nodeValue;
                           UpdateList("noPBHKTrades",xmlDoc.getElementsByTagName("NOPBHKTRADES")[0].childNodes[0].nodeValue);
                           UpdateList("hkMailSent",xmlDoc.getElementsByTagName("HKMAILSENT")[0].childNodes[0].nodeValue);
                 
                  //updating ident 
                   
                  
                  document.getElementById("ideltaCuid").value=xmlDoc.getElementsByTagName("CUID")[0].childNodes[0].nodeValue;
                   document.getElementById("ClientShortName").value=xmlDoc.getElementsByTagName("CLIENTSHORTNAME")[0].childNodes[0].nodeValue;
                   document.getElementById("loanetId").value=xmlDoc.getElementsByTagName("LOANETID")[0].childNodes[0].nodeValue;
                   document.getElementById("cportCode").value=xmlDoc.getElementsByTagName("CPORTCODE")[0].childNodes[0].nodeValue;
                    document.getElementById("crmsOrgId").value=xmlDoc.getElementsByTagName("CRMSORGID")[0].childNodes[0].nodeValue;                  
                     document.getElementById("eqpcsId").value=xmlDoc.getElementsByTagName("EQPCSID")[0].childNodes[0].nodeValue;                  
                  document.getElementById("eqilendIdt").value=xmlDoc.getElementsByTagName("EQUILENTID")[0].childNodes[0].nodeValue;                  
                  document.getElementById("secfinexId").value=xmlDoc.getElementsByTagName("SEXFINEXID")[0].childNodes[0].nodeValue;          


                  //Credit Start
                    document.getElementById("expLimit").value=xmlDoc.getElementsByTagName("EXPLIMIT")[0].childNodes[0].nodeValue;
                    document.getElementById("expLimitCcy").value=xmlDoc.getElementsByTagName("EXPLIMITCCY")[0].childNodes[0].nodeValue;
                    document.getElementById("expLimitPct").value=xmlDoc.getElementsByTagName("EXPLIMITPCT")[0].childNodes[0].nodeValue;
                    document.getElementById("pfeLimit").value=xmlDoc.getElementsByTagName("PFELIMIT")[0].childNodes[0].nodeValue;
                    document.getElementById("settleLimit").value=xmlDoc.getElementsByTagName("SETTLELIMIT")[0].childNodes[0].nodeValue;
                    UpdateList("transfer",xmlDoc.getElementsByTagName("TRANSFER")[0].childNodes[0].nodeValue);
                    UpdateList("clientType",xmlDoc.getElementsByTagName("CLIENTTYPE")[0].childNodes[0].nodeValue);
                    document.getElementById("unsecLimited").value=xmlDoc.getElementsByTagName("UNSECLIMITED")[0].childNodes[0].nodeValue;
                     document.getElementById("singleTradeLimit").value=xmlDoc.getElementsByTagName("SINGLETRADELIMIT")[0].childNodes[0].nodeValue;
                     //Risk Start
                     // document.getElementById("regType").value=xmlDoc.getElementsByTagName("REGTYPE")[0].childNodes[0].nodeValue;
                      document.getElementById("riskPct").value=xmlDoc.getElementsByTagName("RISKPCT")[0].childNodes[0].nodeValue;
                      UpdateList("netAgreement",xmlDoc.getElementsByTagName("NETAGREEMENT")[0].childNodes[0].nodeValue);
                      //Ops start 
                      document.getElementById("basefee").value=xmlDoc.getElementsByTagName("BASEFEECURRENCY")[0].childNodes[0].nodeValue;
                      document.getElementById("mark2market").value=xmlDoc.getElementsByTagName("MARK2MARKETSOURCE")[0].childNodes[0].nodeValue;
                      document.getElementById("marktopolicy").value=xmlDoc.getElementsByTagName("MARKTOMARKETPOLICY")[0].childNodes[0].nodeValue;
                      document.getElementById("externalrecon").value=xmlDoc.getElementsByTagName("EXTERNALRECONSERV")[0].childNodes[0].nodeValue;
                    //Tax Start

                   // UpdateList("w8doc",xmlDoc.getElementsByTagName("W8DOC")[0].childNodes[0].nodeValue);
                     document.getElementById("w3cexpiry").value=xmlDoc.getElementsByTagName("W8EXPDATE")[0].childNodes[0].nodeValue;
                    
                   // UpdateList("dtcclaims",xmlDoc.getElementsByTagName("DTCCLAIMSTRACKED")[0].childNodes[0].nodeValue);
                

                // exposure

                   //Exposure Start
                UpdateList("expMgmtAssigned",xmlDoc.getElementsByTagName("EXPMGTASSIGNED")[0].childNodes[0].nodeValue);
                UpdateList("expMgmtRequired",xmlDoc.getElementsByTagName("EXPMGTREQUIRED")[0].childNodes[0].nodeValue);
                document.getElementById("exposureTolerance").value=xmlDoc.getElementsByTagName("EXPOSURETOLERENCE")[0].childNodes[0].nodeValue;

                 //REHYPO START
                  UpdateList("rehypothecation",xmlDoc.getElementsByTagName("REPHYPOTHECATION")[0].childNodes[0].nodeValue);
                 document.getElementById("rehypoPct").value=xmlDoc.getElementsByTagName("REPHYOPCT")[0].childNodes[0].nodeValue;
                   UpdateList("globalTaxReclaim",xmlDoc.getElementsByTagName("GLOBALTAXRECLAIM")[0].childNodes[0].nodeValue);
                     UpdateList("dbTaxReclaim",xmlDoc.getElementsByTagName("DBTAXRECLAIM")[0].childNodes[0].nodeValue);
                  UpdateList("otherTaxReclaim",xmlDoc.getElementsByTagName("OTHERTAXRECLAIM")[0].childNodes[0].nodeValue);
                   document.getElementById("clientEntityType").value=xmlDoc.getElementsByTagName("CLIENTENTITYTYPE")[0].childNodes[0].nodeValue;
                   UpdateList("clientVote",xmlDoc.getElementsByTagName("CLIENTVOTE")[0].childNodes[0].nodeValue);



  
       }


}



function UpdateList(objname,value)
{
      var lis=document.getElementById(objname);
      // iterating through list 

      //alert(objname);
     
      var strvalue;
       for (var i=0; i<lis.length; i++) 
     {

      strvalue=lis.options[i].value;
      if(strvalue==value)
        {
        // alert("optionvale from list :"+strvalue+"CUSoptionvale :"+value);
         document.getElementById(objname).selectedIndex=i;
         break;
        }
     }
}